package it.aekidna.cleverplatypus.logging
{
  import mx.logging.ILoggingTarget;
  
  import org.springextensions.actionscript.ioc.factory.IInitializingObject;
  import org.springextensions.actionscript.ioc.factory.config.AbstractFactoryObject;
  import org.springextensions.actionscript.utils.Assert;

  /**
   * Creates a new <code>LoggingTargetFactoryObject</code>.
   *
   * <p>The logging target this factory creates will automatically be added to
   * the Log manager class.</p>
   *
   * @example
   *
   * <pre>
   * &lt;object id="traceTarget" class="org.springextensions.actionscript.ioc.factory.config.LoggingTargetFactoryObject"&gt;
   *  &lt;property name="loggingTargetClass" value="mx.logging.targets.TraceTarget"/&gt;
   *  &lt;property name="includeCategory" value="true"/&gt;
   *   &lt;property name="includeDate" value="true"/&gt;
   *  &lt;property name="includeLevel" value="true"/&gt;
   *  &lt;property name="includeTime" value="true"/&gt;
   *   &lt;property name="level" value="2"/&gt;
   *   &lt;property name="filters"&gt;
   *   &lt;array&gt;
   *    &lt;value&gt;com.destination.model.&#42;&lt;/value&gt;
   *    &lt;value&gt;com.destination.view.&#42;&lt;/value&gt;
   *   &lt;/array&gt;
   *  &lt;/property&gt;
   * &lt;/object&gt;
   * </pre>
   *
   * <p>
   * <b>Author:</b> Christophe Herreman<br/>
   * <b>Version:</b> $Revision: 21 $, $Date: 2008-11-01 22:58:42 +0100 (za, 01 nov 2008) $, $Author: dmurat $<br/>
   * <b>Since:</b> 0.1
   * </p>
   */
  public class LocalConnectionLoggingTargetFactory 
  	extends AbstractFactoryObject 
  	implements IInitializingObject 
  {

    private var _loggingTarget:ILoggingTarget;
    private var _loggingTargetClass:Class;
    public var level:uint = 0;
    public var filters:Array = [];
	public var destination : String;
	
    public function LocalConnectionLoggingTargetFactory() 
    {
      super();
    }

    public override function getObject() : * 
    {
      return _loggingTarget;
    }

    public override function getObjectType() : Class 
    {
      return loggingTargetClass;
    }

    /**
     * Create the logging target after all properties have been set.
     */
    public function afterPropertiesSet() : void 
    {
      _loggingTarget = new loggingTargetClass();
      if (_loggingTarget is LocalConnectionLogTarget) {
        var target : LocalConnectionLogTarget = _loggingTarget as LocalConnectionLogTarget;
        target.destination = destination;
      }
      _loggingTarget.filters = filters;
      _loggingTarget.level = level;
    }

    public function get loggingTargetClass() : Class 
    {
      return _loggingTargetClass;
    }

    public function set loggingTargetClass( value : Class ) : void 
    {
      Assert.notNull(value, "The loggingTargetClass must not be null");
      _loggingTargetClass = value;
    }

  }
}
